<template>
    <div class="pad">
        <!-- search start -->
        <!--<searchBar/>-->
        <!-- srach end -->
        <!-- table start  -->
        <tableDataEl
            :page.sync="page"
            :pageSize.sync="pageSize"
            :tableData="tableData.list"
            :tableLabel="tableLabel"
            @handleDetail="handleDetail"
            :pageCount="tableData.rows"
            v-loading="loading"
            height="89vh"
        />
        <!-- table end-->

        <!-- dialog start -->
        <el-dialog
            :visible.sync="isShowDialog"
            center
            title="物料详情"
            width="45%"
            v-el-drag-dialog
        >
            <div class="detail" v-loading="detailLoading">
                <el-form
                    label-width="100px"
                    label-position="left"
                >
                    <el-form-item label="维修厂名称:">
                        {{detailData.company}}
                    </el-form-item>
                    <el-form-item label="维修厂电话:">
                        {{detailData.phone}}
                    </el-form-item>
                    <el-form-item label="详细地址:">
                        {{detailData.province}}{{detailData.city}}{{detailData.county}}{{detailData.address}}
                    </el-form-item>
                    <el-form-item label="供应商:">
                        {{supplier}}
                    </el-form-item>
                </el-form>
                <el-table
                    :data="detailData.detail"
                    border
                >
                    <el-table-column
                        label="物料名称"
                        align="center"
                        prop="materiel"
                        width="250"
                    />
                    <el-table-column
                            label="数量L"
                            align="center"
                            prop="num"
                    />
                    <el-table-column
                            label="备注"
                            align="center"
                            prop="remarks"
                            width="250"
                    />
                </el-table>
            </div>
        </el-dialog>
        <!-- dialog end -->
    </div>
</template>

<script>
    import tableDataEl from '@/views/Setup/common/table'
    export default {
        name: "throughdown",
        components: {
            tableDataEl
        },
        data () {
            return {
                page: 1,
                pageSize: 8,
                tableData: [],
                tableLabel: [
                    {
                        label: '维修厂名称',
                        prop: 'company'
                    },
                    {
                        label: '负责人',
                        prop: 'leader'
                    },
                    {
                        label: '联系方式',
                        prop: 'phone'
                    },
                    {
                        label: '申请时间',
                        prop: 'create_time'
                    },
                    {
                        label: '审核时间',
                        prop: 'audit_time'
                    },
                    {
                        label: '物料详情',
                        detail: true,
                        btnText: '查看',
                        methodName: 'handleDetail'
                    }
                ],
                isShowDialog: false,
                detailData:{},
                supplier: '',
                loading: false,
                detailLoading: false
            }
        },
        methods: {
            async init () { //初始化
                this.loading = true;
                let res = await this.api.log_passList();
                res.code ? this.tableData = res.data: this.$message(res.code);
                this.loading = false;
            },
            async handleDetail (...value) {
                this.detailLoading = true;
                this.isShowDialog = true;
                let res = await this.api.detail({id: value[1]['id']});
                if(res.code) {
                    this.detailData = res.data.list;
                    this.supplier = res.data.gid_array[0]['name'];
                    this.detailLoading = false;
                } else this.$message(res.msg);

            }
        },
        mounted () {
            this.init();
        },
        watch: {
            page() {
                this.init()
            },
            pageSize () {
                this.init()
            }
        }
    }
</script>

<style scoped>
    .pad {
        padding:10px;
    }
    .detail {
        height:385px;
        border:solid 1px #efefef;
        padding:0 10px;
    }
    .el-form-item {
        margin-bottom:5px;
    }
</style>
